/*
 * Copyright (c) 2022  by Junzhao
 * THIS FILE IS PART OF JAVASE Song Huongkang PROJECT
 * All Rights Reserved.
 */

package 线程安全.同步方法;

public class WindowsTest2 {
    public static void main(String[] args) {

        Windows2 wu1 = new Windows2("窗口1");
        Windows2 wu2 = new Windows2("窗口2");
        Windows2 wu3 = new Windows2("窗口3");


        wu1.start();
        wu2.start();
        wu3.start();
    }
}
class Windows2 extends Thread{
    private static int ticket = 1000;


    public Windows2(String name) {
        super(name);
    }

    @Override
    public void run() {
        while(true){
            show();
        }
    }

    private static synchronized void show() {// 同步监视器是 此类 Windows2.class
        try {
            Thread.sleep(6);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        if (ticket>0){
            System.out.println(Thread.currentThread().getName()+"售票 x1 号码为："+ticket);
            ticket--;
        }

    }
}